<?php  if ( ! defined('BASEPATH') ) exit('No direct script access allowed');

/*
 |™*******************************************************************************************™*
 | 								I m a g e    H e l p e r s
 |™*******************************************************************************************™*
*/

/*
 |----------------------------------------------------------------------------------------------
 | Upload Thumb															By Wat, 26-10-2011
 |----------------------------------------------------------------------------------------------
*/
if ( ! function_exists('upload_thumb') ) 
{
	function upload_thumb($file,$upload_path='')
	{
		$ci =& get_instance();
                $ci->load->library('Imaging');
                if($upload_path==''){
                   $upload_path='./uploads/'.$ci->router->class;
                }
                
		$_FILES['thumb'] = $file;			
		
		$objUpload = new Upload($_FILES['thumb']);

		if ($objUpload->uploaded)
		{ 	// file has been uploaded properly
			
			$objUpload->Process($upload_path);
			
			if ($objUpload->processed) {
				
				$data = array(
					'media_type' => $objUpload->file_dst_name_ext,
					'media_name' => $upload_path.'/'.$objUpload->file_dst_name,
					'base_path' => 'uploads/'				
				);
				
				$objUpload->Clean();
				
				return $data;
				
			}
			else
			{
				return FALSE;
			}		
		
		}
		else
		{
			return FALSE;	
		}			
		
	}
} // function_exists



/*
 |----------------------------------------------------------------------------------------------
 | Get Thumb															By Wat, 26-10-2011
 |----------------------------------------------------------------------------------------------
*/
if ( ! function_exists('get_thumb') ) 
{
	function get_thumb($image_path, $width, $height)
	{
		
		// Path to image thumbnail
		$image_thumb = dirname($image_path) . '/thumbs/' . $width . '_' . $height .'/'.basename($image_path);
		$dir_thumb = dirname($image_path) . '/thumbs/' . $width . '_' . $height ;
	
		if( ! file_exists($image_thumb))
		{
			// Create Image Thumb if file Not Exists
			$ci =& get_instance();
		
			$ci->load->library('imaging');
			
			$objUpload = new Upload($image_path);
			
			if ($objUpload->uploaded) { // file has been uploaded properly
				
				$objUpload->image_resize = TRUE;
				$objUpload->image_ratio_crop  = TRUE;
				$objUpload->image_x = $width;
				$objUpload->image_y = $height;
				$objUpload->Process($dir_thumb);
				
			}
		}
		
		return  '/' . $image_thumb ;
	}
} // function_exists


/*
 |----------------------------------------------------------------------------------------------
*/

/* End of file */
/* Location: ./application/helpers/MY_article_helper.php */
